package com.atguigu.day16.array02.t;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.Arrays;
import java.util.Comparator;

public class StudentTest {
    Student[]arr;
    @Before
    public void start(){
        //准备学生对象
        Student s1 = new Student("安琪拉",20,99.5);
        Student s2 = new Student("米莱迪",22,99.4);
        Student s3 = new Student("妲己",21,99.9);
        Student s4 = new Student("庄周",19,99.1);

        //添加到数组内

        arr = new Student[]{s1,s2,s3,s4};
        //排序前输出
        System.out.println("排序前");
        for (Student student : arr) {
            System.out.println(student);
        }
    }
    @After
    public void end(){
        //排序后输出
        System.out.println("排序后");
        for (Student student : arr) {
            System.out.println(student);
        }
    }

@Test
public void test02(){
    //todo 按照分数排序
    SortStudentByScore byScore = new SortStudentByScore();
    Arrays.sort(arr,byScore);

}
@Test
public void test03(){
 //todo 使用匿名内部类完成
    Arrays.sort(arr, new Comparator<Student>() {
        @Override
        public int compare(Student o1, Student o2) {
            return -Double.compare(o1.score,o2.score);
        }
    });
}
    @Test
    public void test01(){
        //排序
        Arrays.sort(arr);

    }
}
class SortStudentByScore implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {

        return Double.compare(o1.score,o2.score);
    }
}